home *** CD-ROM | disk | FTP | other *** search
/ Revista do CD-ROM 123 / cdrom123.iso / essenc / extens / wweb / Web Developer.xpi / chrome / webdeveloper.jar / content / webdeveloper / resize.js < prev    next >
Encoding:
JavaScript  |  2004-11-21  |  4.0 KB  |  103 lines

  1. // Resizes the window to a custom size
  2. function webdeveloper_customWindowSize()
  3. {
  4.     window.openDialog("chrome://webdeveloper/content/dialogs/resize.xul", "webdeveloper-resize-dialog", "centerscreen,chrome,modal", window.outerWidth, window.outerHeight);
  5. }
  6.  
  7. // Displays the resize menu
  8. function webdeveloper_displayResizeMenu(menu, separatorName, tooltips)
  9. {
  10.     const resizeSeparator    = menu.getElementsByAttribute("id", separatorName)[0];
  11.     const preferencesService = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefService).getBranch("");
  12.  
  13.     var description           = null;
  14.     var descriptionPreference = null;
  15.     var height                = null;
  16.     var menuItem              = document.createElement("menuitem");
  17.     var resizeCount           = 0;
  18.     var width                 = null;
  19.  
  20.     // If the resize count preference is set
  21.     if(preferencesService.prefHasUserValue("webdeveloper.resize.count"))
  22.     {
  23.         resizeCount = preferencesService.getIntPref("webdeveloper.resize.count");
  24.     }
  25.  
  26.     webdeveloper_removeGeneratedMenuItems(menu);
  27.  
  28.     // Loop through the possible resize options
  29.     for(var i = 1; i <= resizeCount; i++)
  30.     {
  31.         description = "webdeveloper.resize." + i + ".description";
  32.         height      = "webdeveloper.resize." + i + ".height";
  33.         width       = "webdeveloper.resize." + i + ".width";
  34.  
  35.         // If the description, width and height are set
  36.         if(preferencesService.prefHasUserValue(description) && preferencesService.prefHasUserValue(width) && preferencesService.prefHasUserValue(height))
  37.         {
  38.             descriptionPreference = preferencesService.getCharPref(description).trim();
  39.  
  40.             // If the description is not blank
  41.             if(descriptionPreference != "")
  42.             {
  43.                 menuItem = document.createElement("menuitem");
  44.                 menuItem.setAttribute("class", "webdeveloper-generated-menu");
  45.                 menuItem.setAttribute("label", descriptionPreference);
  46.                 menuItem.setAttribute("oncommand", "webdeveloper_resizeWindow(" + preferencesService.getIntPref(width) + ", " + preferencesService.getIntPref(height) + ")");
  47.  
  48.                 // If displaying tooltips
  49.                 if(tooltips)
  50.                 {
  51.                     menuItem.setAttribute("tooltiptext", descriptionPreference);
  52.                 }
  53.  
  54.                 menu.insertBefore(menuItem, resizeSeparator);
  55.             }
  56.         }
  57.     }
  58. }
  59.  
  60. // Displays the current window size
  61. function webdeveloper_displayWindowSize()
  62. {
  63.     const stringBundle = document.getElementById("webdeveloper-string-bundle");
  64.  
  65.     alert(stringBundle.getFormattedString("webdeveloper_displayWindowSize", [window.outerWidth, window.outerHeight, window.content.innerWidth, window.content.innerHeight]));
  66. }
  67.  
  68. // Displays the current window size in the title bar
  69. function webdeveloper_displayWindowSizeInTitle(element, applyStyle)
  70. {
  71.     const checked = element.getAttribute("checked");
  72.  
  73.     // If the menu is checked
  74.     if(checked)
  75.     {
  76.         window.content.document.title += " - " + window.outerWidth + "x" + window.outerHeight;
  77.         window.onresize                = webdeveloper_updateWindowSizeInTitle;
  78.     }
  79.     else
  80.     {
  81.         const title = window.content.document.title;
  82.  
  83.         window.content.document.title = title.substring(0, title.lastIndexOf(" - "));
  84.         window.onresize               = null;
  85.     }
  86.  
  87.     webdeveloper_toggleStyleSheet(element, "chrome://webdeveloper/content/stylesheets/empty.css", "webdeveloper-display-current-size-title", applyStyle);
  88. }
  89.  
  90. // Resizes the window to the given width and height
  91. function webdeveloper_resizeWindow(width, height)
  92. {
  93.     window.resizeTo(width, height);
  94. }
  95.  
  96. // Updates the window size in the title bar
  97. function webdeveloper_updateWindowSizeInTitle()
  98. {
  99.     const title = window.content.document.title;
  100.  
  101.     window.content.document.title = title.substring(0, title.lastIndexOf(" - ")) + " - " + window.outerWidth + "x" + window.outerHeight;
  102. }
  103.